<?php

abstract class Nimblecms_Controller_Plugin extends Zend_Controller_Plugin_Abstract {
	
	protected $_params = null;
	
	public function __construct() {
		
		//поиск файла конфигурации
		$classname = get_class($this);
		
		$dir = strtolower(substr($classname, 0, -7));
		$paths_array = explode('_', $dir);
		unset($paths_array[0]);
		$paths_array[1] = $paths_array[1] . 's';
                $paths_array[2] = ucfirst($paths_array[2]);
		$dir = implode('_', $paths_array);
                
		
		$file = APPLICATION_PATH . DS . str_replace('_', DS, $dir) . DS . 'config.xml';

		if(!file_exists($file)) 
			throw new Zend_Controller_Exception('File ' . $file . ' not found!', 404);
			
		$this->_params = simplexml_load_file($file);
		
	}
	
	public function getParam($name) {
		if(null === $this->_params)
			return null;
		$xml = $this->_params->xpath("//param[@name='" . addslashes($name) . "']");
		
		return ($xml == null) ? null : $xml[0]->value;
	}
}